package com.yanglun.mvp.presenter;

import android.content.Context;

import com.yanglun.mvp.bean.UserBean;
import com.yanglun.mvp.model.IUserModel;
import com.yanglun.mvp.model.impl.UserModel;
import com.yanglun.mvp.view.IUserView;

/**
 * Created by lyang on 2016/9/13.
 */
public class UserPresenter {
    private IUserView mUserView;
    private IUserModel mUserModel;

    public UserPresenter(IUserView view) {
        mUserView = view;
        mUserModel = new UserModel();
    }

    public void saveUser(Context context) {
        int id = mUserView.getID();
        String firstName = mUserView.getFristName();
        String lastName = mUserView.getLastName();
        mUserModel.setID(id);
        mUserModel.setFirstName(firstName);
        mUserModel.setLastName(lastName);
        mUserModel.save(context);
        mUserView.showToast("保存成功");
    }

    public void loadUser(Context context, int id) {
        UserBean user = mUserModel.load(context,id);
        mUserView.setFirstName(user.getFirstName());
        mUserView.setLastName(user.getLastName());
        mUserView.setID(id);
        mUserView.showToast("读取成功");
    }
}